package org.binglan.youziyuepai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.binglan.youziyuepai.entity.UserFans;
import org.binglan.youziyuepai.mapper.UserFansMapper;
import org.binglan.youziyuepai.service.UserFansService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.binglan.youziyuepai.service.UserService;
import org.binglan.youziyuepai.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户粉丝表 服务实现类
 * </p>
 *
 * @author sanjin
 * @since 2019-04-09
 */
@Service
public class UserFansServiceImpl extends ServiceImpl<UserFansMapper, UserFans> implements UserFansService {

    @Autowired
    UserService userService;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<UserVo> queryFansUserVoByUserId(String userId) {
        UserFans queryUserFans = new UserFans();
        queryUserFans.setUserId(userId);
        List<UserFans> list = list(new QueryWrapper<>(queryUserFans));
        List<UserVo> userVos = new ArrayList<>(list.size());

        list.forEach(item -> {
            UserVo vo = userService.queryUserVoByUserId(item.getFansId());
            userVos.add(vo);
        });
        return userVos;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<UserVo> queryAttentionUserVoByUserId(String userId) {
        UserFans queryUserFans = new UserFans();
        queryUserFans.setFansId(userId);
        List<UserFans> list = list(new QueryWrapper<>(queryUserFans));
        List<UserVo> userVos = new ArrayList<>(list.size());

        list.forEach(item -> {
            UserVo vo = userService.queryUserVoByUserId(item.getUserId());
            userVos.add(vo);
        });
        return userVos;
    }
}
